package com.example.demo.cut;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2023-02-09
 * Time:16:32
 */
@Aspect
//表明这是一个切面
@Component
public class UserAspect {
    //切点方法
    @Pointcut("execution(* com.example.demo.controller.UserController.*(..))")
    public void pointCut(){

    }
    //前置通知
    @Before("pointCut()")
    public void doBefore(){

    }
    //后置通知
    @After("pointCut()")
    public void doAfter(){

    }
    //return 之前的通知
    @AfterReturning("pointCut()")
    public void doAfterReturning(){

    }
    //抛出异常前的通知
    @AfterThrowing("pointCut()")
    public void doAfterThrowing(){

    }
    //环绕通知
    //这个方法需要传入固定参数这个固定参数就是需要做出拦截的类,还需要把这个返回值返回回去
    @Around("pointCut()")
    public Object doAround(ProceedingJoinPoint joinPoint){
        System.out.println("环绕通知的前置");
        Object object=null;
        try {
            object=joinPoint.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println("环绕通知的后置");
        return object;
    }
}
